package com.example.czy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Swagger配置
 *
 * @author czy
 * @date 2024-05-26 21:29:10
 **/
@EnableOpenApi
@Configuration
@EnableWebMvc
public class SwaggerConfig {
    @Bean
    public Docket docket(Environment environment) {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                // Swagger-ui只在开发环境显示
                .enable(environment.acceptsProfiles(Profiles.of("dev")))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.czy"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("API端接口文档")
                .description("更多请咨询服务开发者Operator")
                .contact(new Contact("Operator", "operater.top", "1104815352@qq.com"))
                .version("1.0")
                .build();
    }
}